
import * as moment from 'moment';
import formDataService from './formDataService';
import dTalkApi from '../core/dTalkApi';
import consumerRecoderModel from '../model/consumerRecoderModel';
import visitMonthPlanModel from '../model/visitMonthPlanModel';
import addExportModel from '../model/addExportModel';
import emplModel from '../model/empl2Model';
import dTalkApiUtil from 'dingtalk-app/dtalk/dTalkApiUtil';

class AddService{
    constructor(){}

    //获取当年的某一周的周一到周五的日期
    async getStartDateAndEndDateByWeeks(weeks:number){
        let week=0;
        if(weeks){
            week=weeks;
        }else{
           week= moment().weeks()
        }
        let element2=moment().isoWeeks(week).format('YYYY-MM-DD')
        console.log(element2,'<-------element2-------')
        let now = new Date(); //当前日期  
        let nowDayOfWeek = now.getDay(); //今天本周的第几天  
        let num=nowDayOfWeek-1
        // console.log(nowDayOfWeek,'<--------nowDayOfWeek----------') 
        let startDate=moment(element2).subtract(num,'days').format('YYYY-MM-DD');
        // console.log(startDate,'<----------startDate--------')   //当年的某一周的周一的日期
        let endDate=moment(startDate).add(4,'days').format('YYYY-MM-DD');
        // console.log(endDate,'<------------endDte========')   //当年的某一周的周五的日期
        return {startDate:startDate,endDate:endDate}
    }

    //报表-1    日均的销售拜访率------------按起止日期计算
    async visitRateByDay(startDate1: string, endDate1: string, comment: string, leaderId: string){
        // console.log(startDate1,'startDate1',endDate1,'endDate1',comment,'comment',leaderId,'leaderId')
        let dateData=await formDataService.getDate(startDate1,endDate1)
        let startDate=dateData.startDate;
        let endDate=dateData.endDate;
        let num3 =parseInt( moment(startDate).format('DD'));
        let num4 =parseInt( moment(endDate).format('DD'));
        let access_token=await dTalkApiUtil.getAccessToken();
        let authority=await formDataService.getAuthrity(leaderId,access_token)
        let groupName=authority.groupName;
        let leaderDepts = authority.leaderDepts;
        let dataCache: any = []
        let list:any[]=[]
        let userId:any = '';
        let userList: any[] = [];
        
        // console.log(groupName,'<-------------groupName-')
        if(groupName.includes('全国')||groupName.includes('模块')||groupName.includes('区域')){
            if(leaderDepts.length>0){
                let sonDept:any=[]
                let sonData=await formDataService.getsonDept(leaderDepts,true,access_token);
                let userList2=await formDataService.newArray(sonData.userIdData)
                let son_list2=sonData.list;
                let sonData2:any={}
                if(groupName.includes('区域')||groupName.includes('模块')){
                    sonData2=await formDataService.getsonDept(leaderDepts,false,access_token)
                }
                if (groupName.includes('区域')) {//区域负责人
                    if (comment == '省份') {//已经做完------未测试
                        sonDept=await formDataService.newArray(sonData2.listNames)
                        if(sonDept.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < sonDept.length; sonDeptindex++) {
                                let pro = sonDept[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, comment: 1, deptId: { $in:son_list2 }, userId: { $ne: '' }}); 
                                let consumerRate_area=0;//一个省份的日均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_one_employee=consumerRate_one_employee/(num4-num3+1)
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                // let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:rate.toFixed(2)
                                }
                            }
                        }
                    }        
                }
    
                if(groupName.includes('全国')||groupName.includes('模块')){
                    let sonDept:any=[]
                    let son_area_list:any[]=[]
                    let son_area_list2:any[]=[]
                    let son_province_list:any[]=[]
                    if(groupName.includes('模块')){
                        if(sonData2.list.length==0){
                            son_area_list=[];
                            son_province_list=[];
                        }else if(sonData.list.length==sonData2.list.length&&sonData2.list.length>0){
                            son_province_list=[];
                            son_area_list=sonData2.listNames
                            son_area_list2=sonData2.dept
                        }else if(sonData.list.length !=sonData2.list.length&&sonData2.list.length>0){
                            son_area_list=sonData2.listNames;
                            for (let index2 = 0; index2 <sonData.listNames.length; index2++) {
                                let element = sonData.listNames[index2];
                                if(sonData2.listNames.includes(element)){
                                    son_province_list.push('')
                                }else{
                                    son_province_list.push(element)
                                }
                            }
                        }
                    }
                    if (comment== '区域') {//已经做好
                        let areaNameList:any[]=[]
                        if(groupName.includes('模块')){
                            areaNameList= son_area_list
                        }else if(groupName.includes('全国')){
                            areaNameList=await visitMonthPlanModel.distinct("areaName",{comment:1,"$and":[{areaName:{$ne:null}},{areaName:{$ne:''}}]})
                        }
                        if(areaNameList.length>0){
                            for (let index = 0; index < areaNameList.length; index++) {
                                const element = areaNameList[index];
                                if (!dataCache[element]) {
                                    dataCache[element] = {
                                        areaName:element,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", {areaName:element, deptId: { $in: son_list2 },"$and":[{userId: { $ne: '' }},{userId: { $ne:null}}] });
                                let consumerRate_area=0;//一个区域的日均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_one_employee=consumerRate_one_employee/(num4-num3+1)
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                // console.log(userList.length,'====',element,'=====',consumerRate_area)
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                // let a=(rate.toFixed(2)-0)*100
                                dataCache[element]={
                                    areaName:element,
                                    consumerCount:rate.toFixed(2)
                                }
                            }
                        }
                    }
                    if (comment == '省份') {//已经做完------未测试
                        let provinceNameList:any[]=[]
                        if(groupName.includes('模块')){
                            if(son_province_list.length>0){
                                for (let proindex = 0; proindex < son_province_list.length; proindex++) {
                                    let element2 = son_province_list[proindex];
                                    if(element2){
                                        provinceNameList.push(element2)
                                    }
                                }
                            }
                        }else if(groupName.includes('全国')){
                            provinceNameList=await visitMonthPlanModel.distinct("provinceName",{comment:1,"$and":[{provinceName:{$ne:null}},{provinceName:{$ne:''}}]})
                        }
                        if(provinceNameList.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < provinceNameList.length; sonDeptindex++) {
                                let pro = provinceNameList[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, deptId: { $in:son_list2 }, "$and":[{userId:{$ne:null}},{userId:{$ne:''}}]}); 
                                let consumerRate_area=0;//一个区域的日均拜访率
                                if(userList.length>0){
                                    for (let userindex = 0; userindex < userList.length; userindex++) {
                                        let element2 = userList[userindex];
                                        let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                        consumerRate_one_employee=consumerRate_one_employee/(num4-num3+1)
                                        consumerRate_area+=consumerRate_one_employee;
                                    }
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                // let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:rate.toFixed(2)
                                }
                            }
                        }
                    }
                }
            }
        }
        
        for (const key in dataCache) { //移植dataCache当中的属性到list当中
            if (dataCache.hasOwnProperty(key)) {
                const element = dataCache[key];
                list.push(element)
            }

        }
        if(list.length==0){
            list.push({
                areaName:'',
                consumerCount:0
            })
        }
        console.log(list,'list_list_list_list_list_list_list_list_日均拜访率')
        return list;
    }

    //报表-2  人均的客户拜访率------------按起止日期计算
    async consumerRateByEmp(startDate1: string, endDate1: string, comment: string, leaderId: string){
        // console.log(startDate1,'startDate1',endDate1,'endDate1',comment,'comment',leaderId,'leaderIdr人均')
        let dateData=await formDataService.getDate(startDate1,endDate1)
        let startDate=dateData.startDate;
        let endDate=dateData.endDate;
        let num3 =parseInt( moment(startDate).format('DD'));
        let num4 =parseInt( moment(endDate).format('DD'));
        let access_token=await dTalkApiUtil.getAccessToken();
        let authority=await formDataService.getAuthrity(leaderId,access_token)
        let groupName=authority.groupName;
        let leaderDepts = authority.leaderDepts;
        let dataCache: any = []
        let list:any[]=[]
        let userId:any = '';
        let userList: any[] = [];
        
        // console.log(groupName,'<-------------groupName2222222222-')
        if(groupName.includes('全国')||groupName.includes('模块')||groupName.includes('区域')){
            if(leaderDepts.length>0){
                let sonDept:any=[]
                let sonData=await formDataService.getsonDept(leaderDepts,true,access_token);
                let userList2=await formDataService.newArray(sonData.userIdData)
                let son_list2=sonData.list;
                let sonData2:any={}
                if(groupName.includes('区域')||groupName.includes('模块')){
                    sonData2=await formDataService.getsonDept(leaderDepts,false,access_token)
                }
                if (groupName.includes('区域')) {//区域负责人
                    if (comment == '省份') {//已经做完------未测试
                        sonDept=await formDataService.newArray(sonData2.listNames)
                        if(sonDept.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < sonDept.length; sonDeptindex++) {
                                let pro = sonDept[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, deptId: { $in:son_list2 }, "$and":[{userId:{$ne:null}},{userId:{$ne:''}}]}); 
                                let consumerRate_area=0;//一个省份的人均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                // let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:rate.toFixed(0)
                                }
                            }
                        }
                    }        
                }
                if(groupName.includes('全国')||groupName.includes('模块')){
                    let sonDept:any=[]
                    let son_area_list:any[]=[]
                    let son_area_list2:any[]=[]
                    let son_province_list:any[]=[]
                    if(groupName.includes('模块')){
                        if(sonData2.list.length==0){
                            son_area_list=[];
                            son_province_list=[];
                        }else if(sonData.list.length==sonData2.list.length&&sonData2.list.length>0){
                            son_province_list=[];
                            son_area_list=sonData2.listNames
                            son_area_list2=sonData2.dept
                        }else if(sonData.list.length !=sonData2.list.length&&sonData2.list.length>0){
                            son_area_list=sonData2.listNames;
                            for (let index2 = 0; index2 <sonData.listNames.length; index2++) {
                                let element = sonData.listNames[index2];
                                if(sonData2.listNames.includes(element)){
                                    son_province_list.push('')
                                }else{
                                    son_province_list.push(element)
                                }
                            }
                        }
                    }
                    if (comment== '区域') {//已经做好
                        let areaNameList:any[]=[]
                        if(groupName.includes('模块')){
                            areaNameList= son_area_list
                        }else if(groupName.includes('全国')){
                            areaNameList=await visitMonthPlanModel.distinct("areaName",{comment:1,"$and":[{areaName:{$ne:null}},{areaName:{$ne:''}}]})
                        }
                        if(areaNameList.length>0){
                            for (let index = 0; index < areaNameList.length; index++) {
                                const element = areaNameList[index];
                                if (!dataCache[element]) {
                                    dataCache[element] = {
                                        areaName:element,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", {areaName:element, deptId: { $in: son_list2 },"$and":[{userId: { $ne: '' }},{userId: { $ne:null}}] });
                                let consumerRate_area=0;//一个区域的人均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                // let a=(rate.toFixed(2)-0)*100
                                dataCache[element]={
                                    areaName:element,
                                    consumerCount:rate.toFixed(0)
                                }
                            }
                        }
                    }
                    if (comment == '省份') {//已经做完------未测试
                        let provinceNameList:any[]=[]
                        if(groupName.includes('模块')){
                            if(son_province_list.length>0){
                                for (let proindex = 0; proindex < son_province_list.length; proindex++) {
                                    let element2 = son_province_list[proindex];
                                    if(element2){
                                        provinceNameList.push(element2)
                                    }
                                }
                            }
                        }else if(groupName.includes('全国')){
                            provinceNameList=await visitMonthPlanModel.distinct("provinceName",{comment:1,"$and":[{provinceName:{$ne:null}},{provinceName:{$ne:''}}]})
                        }
                        if(provinceNameList.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < provinceNameList.length; sonDeptindex++) {
                                let pro = provinceNameList[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, deptId: { $in:son_list2 }, "$and":[{userId: { $ne: '' }},{userId: { $ne:null}}]  }); 
                                let consumerRate_area=0;//一个区域的日均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                // let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:rate.toFixed(0)
                                }
                            }
                        }
                    }
                }
            }
        }
        for (const key in dataCache) { //移植dataCache当中的属性到list当中
            if (dataCache.hasOwnProperty(key)) {
                const element = dataCache[key];
                list.push(element)
            }
        }
        if(list.length==0){
            list.push({
                areaName:'',
                consumerCount:0
            })
        }
        console.log(list,'list_list_list_list_list_list_list_list_人均客户拜访率')
        return list;
    }



    //日均的销售拜访率2
    async visitRateByDay2(startDate1: string, endDate1: string,character:string, comment: string, leaderId: string){
        let dateData=await formDataService.getDate(startDate1,endDate1)
        let startDate=dateData.startDate;
        let endDate=dateData.endDate;
        let num3 =parseInt( moment(startDate).format('DD'));
        let num4 =parseInt( moment(endDate).format('DD'));
        let access_token=await dTalkApiUtil.getAccessToken();
        let authority=await formDataService.getAuthrity(leaderId,access_token)
        let groupName=authority.groupName;
        let leaderDepts = authority.leaderDepts;
        let dataCache: any = []
        let list:any[]=[]
        let userId:any = '';
        let userList: any[] = [];
       
        if(groupName.includes('全国')||groupName.includes('模块')||groupName.includes('区域')||groupName.includes('省份')){
            if(leaderDepts.length>0){
                let sonDept:any=[]
                let sonData=await formDataService.getsonDept(leaderDepts,true,access_token);
                let userList2=await formDataService.newArray(sonData.userIdData)
                let son_list2=sonData.list;
                let sonData2:any={}
                if(comment=='个人'){
                    if(character){
                        let userId=character;
                        let userInfo = await dTalkApi.getUserDetail(userId,access_token);
                        let name:any='';
                        if (userInfo&&userInfo.name) {
                            name=userInfo.name
                        } else {
                            let data5=await visitMonthPlanModel.findOne({userId:userId,'$and':[{user:{$ne:null}},{user:{$ne:''}}]})
                            if(data5){
                                name=data5.user
                            }
                        }
                        let dateList=await formDataService.getDate2(num3,num4,startDate)//日期
                        if(dateList.length>0){
                            for (let index = 0; index < dateList.length; index++) {
                                let date = dateList[index];
                                let consumerCount_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(userId, date, date);
                                dataCache.push({
                                    userId:userId,
                                    comment: '一天',
                                    userName: name,
                                    date:date,
                                    consumerCount: consumerCount_one_employee.toFixed(0)
                                })
                            }
                        }
                    }else{
                        if(userList2.length>0){
                            for (let index = 0; index < userList2.length; index++) {
                                let it = userList2[index];
                                let emp=await visitMonthPlanModel.findOne({userId:it,"$and":[{user:{$ne:''}},{user:{$ne:null}}]})
                                if (!dataCache[emp.user]) {
                                    dataCache[emp.user] = {
                                        areaName:emp.user,
                                        consumerCount:''
                                    }
                                }
                                let consumerCount_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(it, startDate, endDate);
                                consumerCount_one_employee=consumerCount_one_employee/(num4-num3+1);
                                let rate:any=consumerCount_one_employee;
                                // let a=(rate.toFixed(2)-0)*100
                                dataCache[emp.user]={
                                    areaName:emp.user,
                                    consumerCount:rate.toFixed(0)
                                }
                            } 
                        }
                    }
                }
                if(groupName.includes('区域')||groupName.includes('模块')){
                    sonData2=await formDataService.getsonDept(leaderDepts,false,access_token)
                }
                if (groupName.includes('区域')) {//区域负责人
                    if (comment == '省份') {//已经做完------未测试
                        sonDept=await formDataService.newArray(sonData2.listNames)
                        if(sonDept.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < sonDept.length; sonDeptindex++) {
                                let pro = sonDept[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, comment: 1, deptId: { $in:son_list2 }, userId: { $ne: '' }}); 
                                let consumerRate_area=0;//一个省份的日均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_one_employee=consumerRate_one_employee/(num4-num3+1)
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:a.toFixed(0)
                                }
                            }
                        }
                    }        
                }
                if(groupName.includes('全国')||groupName.includes('模块')){
                    let sonDept:any=[]
                    let son_area_list:any[]=[]
                    let son_province_list:any[]=[]
                    if(groupName.includes('模块')){
                        if(sonData2.list.length==0){
                            son_area_list=[];
                            son_province_list=[];
                        }else if(sonData.list.length==sonData2.list.length&&sonData2.list.length>0){
                            son_province_list=[];
                            son_area_list=sonData2.listNames
                        }else if(sonData.list.length !=sonData2.list.length&&sonData2.list.length>0){
                            son_area_list=sonData2.listNames;
                            for (let index2 = 0; index2 <sonData.listNames.length; index2++) {
                                let element = sonData.listNames[index2];
                                if(sonData2.listNames.includes(element)){
                                    son_province_list.push('')
                                }else{
                                    son_province_list.push(element)
                                }
                            }
                        }
                    }
                    if (comment== '区域') {//已经做好
                        let areaNameList:any[]=[]
                        if(groupName.includes('模块')){
                            areaNameList= son_area_list
                        }else if(groupName.includes('全国')){
                            areaNameList=await visitMonthPlanModel.distinct("areaName",{comment:1,"$and":[{areaName:{$ne:null}},{areaName:{$ne:''}}]})
                        }
                        if(areaNameList.length>0){
                            for (let index = 0; index < areaNameList.length; index++) {
                                const element = areaNameList[index];
                                if (!dataCache[element]) {
                                    dataCache[element] = {
                                        areaName:element,
                                        consumerCount:''
                                    }
                                }
                                let areaId=await visitMonthPlanModel.findOne({areaName:element,"$and":[{area:{$ne:null}},{area:{$ne:''}}]})
                                let sonData3 = await dTalkApi.getSondepIdList(areaId.area, true,access_token);
                                let son_list3 = sonData3.department;
                                son_list3.push(parseInt(areaId.area));//区域id列表
                                userList = await visitMonthPlanModel.distinct("userId", { deptId: { $in: son_list3 },"$and":[{userId: { $ne: '' }},{userId: { $ne:null}}] });
                              
                               
                                let consumerRate_area=0;//一个区域的日均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_one_employee=consumerRate_one_employee/(num4-num3+1)
                                    // if(element=='上海'){
                                    //     console.log(consumerRate_one_employee,'consumerRate_one_employee',element2)
                                    // }
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                // if(element=='上海'){
                                //     console.log(userList,'userList_userList_userList_userList_',element,'<---------',consumerRate_area)
                                // }
                               
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                let a=(rate.toFixed(2)-0)*100
                                dataCache[element]={
                                    areaName:element,
                                    consumerCount:a.toFixed(0)
                                }
                            }
                        }
                    }
                    if (comment == '省份') {//已经做完------未测试
                        let provinceNameList:any[]=[]
                        if(groupName.includes('模块')){
                            if(son_province_list.length>0){
                                for (let proindex = 0; proindex < son_province_list.length; proindex++) {
                                    let element2 = son_province_list[proindex];
                                    if(element2){
                                        provinceNameList.push(element2)
                                    }
                                }
                            }
                        }else if(groupName.includes('全国')){
                            provinceNameList=await visitMonthPlanModel.distinct("provinceName",{comment:1,"$and":[{provinceName:{$ne:null}},{provinceName:{$ne:''}}]})
                        }
                        if(provinceNameList.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < provinceNameList.length; sonDeptindex++) {
                                let pro = provinceNameList[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, deptId: { $in:son_list2 }, "$and":[{userId:{$ne:null}},{userId:{$ne:''}}]}); 
                                let consumerRate_area=0;//一个区域的日均拜访率
                                if(userList.length>0){
                                    for (let userindex = 0; userindex < userList.length; userindex++) {
                                        let element2 = userList[userindex];
                                        let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                        consumerRate_one_employee=consumerRate_one_employee/(num4-num3+1)
                                        consumerRate_area+=consumerRate_one_employee;
                                    }
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:a.toFixed(0)
                                }
                            }
                        }
                    }
                }
            }
        }
        for (const key in dataCache) { //移植dataCache当中的属性到list当中
            if (dataCache.hasOwnProperty(key)) {
                const element = dataCache[key];
                list.push(element)
            }
        }
        if(list.length==0){
            list.push({
                areaName:'',
                consumerCount:0
            })
        }
        console.log(list,'list_list_list_list_list_list_list_list_日均拜访率2')
        return list;
    }

    //人均的客户拜访率2
    async consumerRateByEmp2(startDate1: string, endDate1: string,character:string, comment: string, leaderId: string){
        let dateData=await formDataService.getDate(startDate1,endDate1)
        let startDate=dateData.startDate;
        let endDate=dateData.endDate;
        let num3 =parseInt( moment(startDate).format('DD'));
        let num4 =parseInt( moment(endDate).format('DD'));
        let access_token=await dTalkApiUtil.getAccessToken();
        let authority=await formDataService.getAuthrity(leaderId,access_token)
        let groupName=authority.groupName;
        let leaderDepts = authority.leaderDepts;
        let dataCache: any = []
        let list:any[]=[]
        let userId:any = '';
        let userList: any[] = [];
        
        if(groupName.includes('全国')||groupName.includes('模块')||groupName.includes('区域')||groupName.includes('省份')){
            if(leaderDepts.length>0){
                let sonDept:any=[]
                let sonData=await formDataService.getsonDept(leaderDepts,true,access_token);
                let userList2=await formDataService.newArray(sonData.userIdData)
                let son_list2=sonData.list;
                let sonData2:any={}
                if(comment=='个人'){
                    if(character){
                        let userId=character;
                        let userInfo=await dTalkApi.getUserDetail(userId,access_token);
                        let name:any='';
                        if(userInfo&&userInfo.name){
                            name=userInfo.name;
                        }else{
                            let data5=await visitMonthPlanModel.findOne({userId:userId,'$and':[{user:{$ne:null}},{user:{$ne:''}}]})
                            if(data5){
                                name=data5.user
                            }
                        }
                        let dateList=await formDataService.getDate2(num3,num4,startDate);
                        if(dateList.length>0){
                            for(let index=0;index<dateList.length;index++){
                                let date=dateList[index];
                                let consumerCount_one_employee=await formDataService.getCountConsumer_one_employeeDate1ToDate2(userId,date,date);
                                dataCache.push({
                                    comment:'一天',
                                    userId:userId,
                                    userName:name,
                                    date:date,
                                    consumerCount:consumerCount_one_employee.toFixed(0)
                                })
                            }
                        }
                    }else{
                        if(userList2.length>0){
                            for(let index2=0;index2<userList2.length;index2++){
                                let id=userList2[index2];
                                let emp=await visitMonthPlanModel.findOne({userId:id,'$and':[{user:{$ne:null}},{user:{$ne:''}}]})
                                if(!dataCache[emp.user]){
                                    dataCache[emp.user]={
                                        areaName:emp.user,
                                        consumerCount:''
                                    }
                                }
                                let consumerCount_one_employee=await formDataService.getCountConsumer_one_employeeDate1ToDate2(id,startDate,endDate);
                                consumerCount_one_employee=consumerCount_one_employee/(num4-num3+1);
                                let rate:any=consumerCount_one_employee;
                                dataCache[emp.user]={
                                    areaName:emp.user,
                                    consumerCount:rate.toFixed(0)
                                }
                            }
                        }
                    }
                }
                if(groupName.includes('区域')||groupName.includes('模块')){
                    sonData2=await formDataService.getsonDept(leaderDepts,false,access_token)
                }
                if (groupName.includes('区域')) {//区域负责人
                    if (comment == '省份') {//已经做完------未测试
                        sonDept=await formDataService.newArray(sonData2.listNames)
                        if(sonDept.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < sonDept.length; sonDeptindex++) {
                                let pro = sonDept[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, deptId: { $in:son_list2 }, "$and":[{userId:{$ne:null}},{userId:{$ne:''}}]}); 
                                let consumerRate_area=0;//一个省份的人均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:a.toFixed(0)
                                }
                            }
                        }
                    }        
                }
    
                if(groupName.includes('全国')||groupName.includes('模块')){
                    let sonDept:any=[]
                    let son_area_list:any[]=[]
                    let son_province_list:any[]=[]
                    if(groupName.includes('模块')){
                        if(sonData2.list.length==0){
                            son_area_list=[];
                            son_province_list=[];
                        }else if(sonData.list.length==sonData2.list.length&&sonData2.list.length>0){
                            son_province_list=[];
                            son_area_list=sonData2.listNames
                        }else if(sonData.list.length !=sonData2.list.length&&sonData2.list.length>0){
                            son_area_list=sonData2.listNames;
                            for (let index2 = 0; index2 <sonData.listNames.length; index2++) {
                                let element = sonData.listNames[index2];
                                if(sonData2.listNames.includes(element)){
                                    son_province_list.push('')
                                }else{
                                    son_province_list.push(element)
                                }
                            }
                        }
                    }
                    if (comment== '区域') {//已经做好
                        let areaNameList:any[]=[]
                        if(groupName.includes('模块')){
                            areaNameList= son_area_list
                        }else if(groupName.includes('全国')){
                            areaNameList=await visitMonthPlanModel.distinct("areaName",{comment:1,"$and":[{areaName:{$ne:null}},{areaName:{$ne:''}}]})
                        }
                        if(areaNameList.length>0){
                            for (let index = 0; index < areaNameList.length; index++) {
                                const element = areaNameList[index];
                                if (!dataCache[element]) {
                                    dataCache[element] = {
                                        areaName:element,
                                        consumerCount:''
                                    }
                                }
                                let areaId=await visitMonthPlanModel.findOne({areaName:element,"$and":[{area:{$ne:null}},{area:{$ne:''}}]})
                                let sonData3 = await dTalkApi.getSondepIdList(areaId.area, true,access_token);
                                let son_list3 = sonData3.department;
                                son_list3.push(parseInt(areaId.area));//区域id列表
                                userList = await visitMonthPlanModel.distinct("userId", { deptId: { $in: son_list3 },"$and":[{userId: { $ne: '' }},{userId: { $ne:null}}] });
                                let consumerRate_area=0;//一个区域的人均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                let a=(rate.toFixed(2)-0)*100
                                dataCache[element]={
                                    areaName:element,
                                    consumerCount:a.toFixed(0)
                                }
                            }
                        }
                    }
                    if (comment == '省份') {//已经做完------未测试
                        let provinceNameList:any[]=[]
                        if(groupName.includes('模块')){
                            if(son_province_list.length>0){
                                for (let proindex = 0; proindex < son_province_list.length; proindex++) {
                                    let element2 = son_province_list[proindex];
                                    if(element2){
                                        provinceNameList.push(element2)
                                    }
                                }
                            }
                        }else if(groupName.includes('全国')){
                            provinceNameList=await visitMonthPlanModel.distinct("provinceName",{comment:1,"$and":[{provinceName:{$ne:null}},{provinceName:{$ne:''}}]})
                        }
                        if(provinceNameList.length>0){
                            for (let sonDeptindex = 0; sonDeptindex < provinceNameList.length; sonDeptindex++) {
                                let pro = provinceNameList[sonDeptindex];
                                if (!dataCache[pro]) {
                                    dataCache[pro] = {
                                        areaName:pro,
                                        consumerCount:''
                                    }
                                }
                                userList = await visitMonthPlanModel.distinct("userId", { provinceName:pro, deptId: { $in:son_list2 }, "$and":[{userId: { $ne: '' }},{userId: { $ne:null}}]  }); 
                                let consumerRate_area=0;//一个区域的日均拜访率
                                for (let userindex = 0; userindex < userList.length; userindex++) {
                                    let element2 = userList[userindex];
                                    let consumerRate_one_employee = await formDataService.getCountConsumer_one_employeeDate1ToDate2(element2, startDate, endDate);
                                    consumerRate_area+=consumerRate_one_employee;
                                }
                                let rate:any=0;
                                if(userList.length>0){
                                    rate=(consumerRate_area/userList.length);
                                }else{
                                    rate=0
                                }
                                let a=(rate.toFixed(2)-0)*100
                                dataCache[pro]={
                                    areaName:pro,
                                    consumerCount:a.toFixed(0)
                                }
                            }
                        }
                    }
                }
            }
        }
        for (const key in dataCache) { //移植dataCache当中的属性到list当中
            if (dataCache.hasOwnProperty(key)) {
                const element = dataCache[key];
                list.push(element)
            }
        }
        if(list.length==0){
            list.push({
                areaName:'',
                consumerCount:0
            })
        }
        console.log(list,'list_list_list_list_list_list_list_list_人均客户拜访率2')
        return list;
    }





    //导出报表-------------日均拜访率
    async exportConsumerCountByDay(startDate1:string,endDate1:string,leaderId:string,comment:string){
        console.log(startDate1,endDate1,leaderId,comment,'<-------------')
        let dateData=await formDataService.getDate(startDate1,endDate1)
        let startDate=dateData.startDate
        let endDate=dateData.endDate
        let date1 = parseInt(moment(startDate).format('DD'))
        let date2 = parseInt(moment(endDate).format('DD'))
        let access_token=await dTalkApiUtil.getAccessToken();
        let conf:any[]=[]
        let dateList:any[]=[]
        let col:any[]=[]
        col.push('区域名称')
        col.push('部门id')
        for(let index=0;index<=(date2-date1);index++){
            let newDate=moment(startDate).add(index,'days').format('YYYY-MM-DD')
            col.push(newDate+'(日均拜访数量)')
            dateList.push(newDate)
        }
        col.push('日均拜访总数量')
        conf.push(col)
        let authority=await formDataService.getAuthrity(leaderId,access_token);
        let groupName=authority.groupName
        let leaderDepts=authority.leaderDepts
        if(groupName.includes('全国')||groupName.includes('模块')||groupName.includes('区域')){
            if(leaderDepts.length>0){
                let sonData=await formDataService.getsonDept(leaderDepts,true,access_token)
                // let userList=await formDataService.newArray(sonData.userIdData)
                let listNames:any[]=[]  //sonData2.listNames
                let son_area_list2:any[]=[]  //sonData2.dept
                let son_province_list:any[]=[]  
                if(groupName.includes('模块')||groupName.includes('区域')){
                    let sonData2=await formDataService.getsonDept(leaderDepts,false,access_token)
                    if(groupName.includes('区域')){
                        listNames=sonData2.listNames
                    }
                    if(groupName.includes('模块')){
                        if(sonData2.listNames.length==0){
                            listNames=[];
                        }else if(sonData.listNames.length==sonData2.listNames.length&&sonData2.listNames.length>0){
                            listNames=sonData2.listNames
                            son_area_list2=sonData2.dept
                        }else if(sonData.list.length !=sonData2.list.length&&sonData2.list.length>0){
                            listNames=sonData2.listNames;
                            for (let index2 = 0; index2 <sonData.listNames.length; index2++) {
                                let element = sonData.listNames[index2];
                                if(sonData2.listNames.includes(element)){
                                    son_province_list.push('')
                                }else{
                                    son_province_list.push(element)
                                }
                            }
                        }
                    }
                }
                if(comment=='区域'){
                    if(groupName.includes('全国')){
                        listNames=await visitMonthPlanModel.distinct('areaName',{'$and':[{areaName:{$ne:null}},{areaName:{$ne:''}}]})
                    }
                    if(listNames.length>0){
                        for(let listindex=0;listindex<listNames.length;listindex++){
                            let name=listNames[listindex]
                            let m_data:any[]=[]
                            m_data.push(name)
                            let data2=await visitMonthPlanModel.findOne({areaName:name,'$and':[{area:{$ne:null}},{area:{$ne:''}}]})
                            if(data2&&data2.area){
                                m_data.push(data2.area)
                            }else{
                                m_data.push('')
                            }
                            let consumerCount_total:any=0
                            for (let index2 = 0; index2 < dateList.length; index2++) {
                                let date = dateList[index2];
                                let data=await addExportModel.findOne({name_:name,date_:date})
                                consumerCount_total+=data.consumerCount_day
                                if(data){
                                    m_data.push(data.consumerCount_day)
                                }else{
                                    m_data.push('')
                                }
                            }
                            m_data.push(consumerCount_total)
                            conf.push(m_data)
                        }
                    }
                }

                if(comment=='省份'){
                    let areaNameList:any[]=[]
                    if(groupName.includes('全国')){
                        areaNameList=await visitMonthPlanModel.distinct('provinceName',{'$and':[{provinceName:{$ne:null}},{provinceName:{$ne:''}}]})
                    }else{
                        areaNameList=son_province_list    
                    }
                    if(areaNameList.length>0){
                        for (let index4 = 0; index4 < areaNameList.length; index4++) {
                            let pro = areaNameList[index4];
                            if(!pro){
                                continue;
                            }
                            let m_data:any[]=[]
                            m_data.push(name)
                            let data2=await visitMonthPlanModel.findOne({provinceName:pro,'$and':[{province:{$ne:null}},{province:{$ne:''}}]})
                            if(data2&&data2.province){
                                m_data.push(data2.province)
                            }else{
                                m_data.push('')
                            }
                            let consumerCount_total:any=0
                            for (let index5 = 0; index5 < dateList.length; index5++) {
                                let date = dateList[index5];
                                let data=await addExportModel.findOne({name_:pro,date_:date})
                                consumerCount_total+=data.consumerCount_day
                                if(data){
                                    m_data.push(data.consumerCount_day)
                                }else{
                                    m_data.push('')
                                }
                            }
                            m_data.push(consumerCount_total)
                            conf.push(m_data)
                        }
                    }
                }
            }
        }
        console.log(conf,'conf_conf_conf_conf_conf_conf_日均拜访率导出')
        return conf
    }


    //导出报表-------------人均拜访率
    async exportConsumerCountByEmp(startDate1:string,endDate1:string,leaderId:string,comment:string){
        let dateData=await formDataService.getDate(startDate1,endDate1)
        let startDate=dateData.startDate
        let endDate=dateData.endDate
        let date1 = parseInt(moment(startDate).format('DD'))
        let date2 = parseInt(moment(endDate).format('DD'))
        let access_token=await dTalkApiUtil.getAccessToken();
        let conf:any[]=[]
        let dateList:any[]=[]
        let col:any[]=[]
        col.push('区域名称')
        col.push('部门id')
        for(let index=0;index<=(date2-date1);index++){
            let newDate=moment(startDate).add(index,'days').format('YYYY-MM-DD')
            col.push(newDate+'(人均拜访数量)')
            dateList.push(newDate)
        }
        col.push('人均拜访总数量')
        conf.push(col)
        let authority=await formDataService.getAuthrity(leaderId,access_token);
        let groupName=authority.groupName
        let leaderDepts=authority.leaderDepts
        if(groupName.includes('全国')||groupName.includes('模块')||groupName.includes('区域')){
            if(leaderDepts.length>0){
                let sonData=await formDataService.getsonDept(leaderDepts,true,access_token)
                // let userList=await formDataService.newArray(sonData.userIdData)
                let listNames:any[]=[]  //sonData2.listNames
                let son_area_list2:any[]=[]  //sonData2.dept
                let son_province_list:any[]=[]  
                if(groupName.includes('模块')||groupName.includes('区域')){
                    let sonData2=await formDataService.getsonDept(leaderDepts,false,access_token)
                    if(groupName.includes('区域')){
                        listNames=sonData2.listNames
                    }
                    if(groupName.includes('模块')){
                        if(sonData2.listNames.length==0){
                            listNames=[];
                        }else if(sonData.listNames.length==sonData2.listNames.length&&sonData2.listNames.length>0){
                            listNames=sonData2.listNames
                            son_area_list2=sonData2.dept
                        }else if(sonData.list.length !=sonData2.list.length&&sonData2.list.length>0){
                            listNames=sonData2.listNames;
                            for (let index2 = 0; index2 <sonData.listNames.length; index2++) {
                                let element = sonData.listNames[index2];
                                if(sonData2.listNames.includes(element)){
                                    son_province_list.push('')
                                }else{
                                    son_province_list.push(element)
                                }
                            }
                        }
                    }
                }
                if(comment=='区域'){
                    if(groupName.includes('全国')){
                        listNames=await visitMonthPlanModel.distinct('areaName',{'$and':[{areaName:{$ne:null}},{areaName:{$ne:''}}]})
                    }
                    if(listNames.length>0){
                        for(let listindex=0;listindex<listNames.length;listindex++){
                            let name=listNames[listindex]
                            let m_data:any[]=[]
                            m_data.push(name)
                            let data2=await visitMonthPlanModel.findOne({areaName:name,'$and':[{area:{$ne:null}},{area:{$ne:''}}]})
                            if(data2&&data2.area){
                                m_data.push(data2.area)
                            }else{
                                m_data.push('')
                            }
                            let consumerCount_total:any=0
                            if(dateList.length>0){
                                for (let index2 = 0; index2 < dateList.length; index2++) {
                                    let date = dateList[index2];
                                    let data=await addExportModel.findOne({name_:name,date_:date})
                                    if(data&&data.consumerCount_empl){
                                        consumerCount_total+=data.consumerCount_empl
                                    }
                                    
                                    if(data){
                                        m_data.push(data.consumerCount_empl)
                                    }else{
                                        m_data.push('')
                                    }
                                }
                            }
                            m_data.push(consumerCount_total)
                            conf.push(m_data)
                        }
                    }
                }
                
                if(comment=='省份'){
                    let areaNameList:any[]=[]
                    if(groupName.includes('全国')){
                        areaNameList=await visitMonthPlanModel.distinct('provinceName',{'$and':[{provinceName:{$ne:null}},{provinceName:{$ne:''}}]})
                    }else{
                        areaNameList=son_province_list    
                    }
                    if(areaNameList.length>0){
                        for (let index4 = 0; index4 < areaNameList.length; index4++) {
                            let pro = areaNameList[index4];
                            if(!pro){
                                continue;
                            }
                            let m_data:any[]=[]
                            m_data.push(pro)
                            let data2=await visitMonthPlanModel.findOne({provinceName:pro,'$and':[{province:{$ne:null}},{province:{$ne:''}}]})
                            if(data2&&data2.province){
                                m_data.push(data2.province)
                            }else{
                                m_data.push('')
                            }
                            let consumerCount_total:any=0
                            for (let index5 = 0; index5 < dateList.length; index5++) {
                                let date = dateList[index5];
                                let data=await addExportModel.findOne({name_:pro,date_:date})
                                consumerCount_total+=data.consumerCount_empl
                                if(data){
                                    m_data.push(data.consumerCount_empl)
                                }else{
                                    m_data.push('')
                                }
                            }
                            m_data.push(consumerCount_total)
                            conf.push(m_data)
                        }
                    }
                }
            }
        }
        console.log(conf,'conf_conf_conf_conf_conf_conf_日均拜访率导出')
        return conf;
    }

    //从钉钉获取人员信息
    async getEmplFromDD(){
        console.log('获取部门人员开始!!!!!!!!!!')
        let ACCESS_TOKEN = await dTalkApiUtil.getAccessToken();
        let data=await dTalkApi.getSondepIdList('1',true,ACCESS_TOKEN);
        let deptIdList:any=data.department;
        deptIdList.push(1);
        let count=await emplModel.count({})
        console.log(count,'count_count_count')
        if(count>0){
            let b= await emplModel.remove({})
            console.log('delete',b,'b_b_b_b_b_')
        }
        if(deptIdList.length>0){
            for (let index = 0; index < deptIdList.length; index++) {
                let id = deptIdList[index];
                //let data=await organiseModel.findOne({deptId:id,'$and':[{deptName:{$ne:''}},{deptName:{$ne:null}}]})
                let empdata=await dTalkApi.getDeptEmplDetail(id,ACCESS_TOKEN);
                //console.log(empdata,'<------------>')
                if(empdata&&empdata.userlist){
                    let empList:any[]=empdata.userlist
                    if(empList.length>0){
                        for (let empindex = 0; empindex < empList.length; empindex++) {
                            let emp = empList[empindex];
                            //console.log(emp,'emp_______________________________')
                            let data1=await emplModel.findOne({userId:emp.userid})
                            if(data1){
                                //console.log('修改!!!!!!!1'+emp.userid+'----'+data1.userName)
                                let a_= await emplModel.update({userId:emp.userid},{
                                    userId: emp.userid,
                                    userName: emp.name,
                                    avatar:emp.avatar,
                                    mobile:emp.mobile,//手机号码
                                    tel:emp.tel,//座机电话
                                    deptId:emp.department,
                                    isLeader:emp.isLeader,   //是否是部门主管
                                    isAdmin:emp.isAdmin,    //是否是企业管理员
                                    isBoss:emp.isBoss,     //是否是企业老板
                                    status:'',//用户当前状态
                                    job:emp.position,//职位
                                    userEmail:emp.email,
                                    jobnumber:emp.jobnumber,   //用户工号
                                    userArea:emp.workPlace,
                                    timestamp:moment().format('YYYY-MM-DD HH:mm:ss'),
                                    comment:1
                                })
                            }else{
                                console.log('添加!!!!!!!1',emp.name,'=====dept====',id)
                                let b=await emplModel.create({
                                    userId: emp.userid,
                                    userName: emp.name,
                                    avatar:emp.avatar,
                                    mobile:emp.mobile,//手机号码
                                    tel:emp.tel,//座机电话
                                    deptId:emp.department,
                                    isLeader:emp.isLeader,   //是否是部门主管
                                    isAdmin:emp.isAdmin,    //是否是企业管理员
                                    isBoss:emp.isBoss,     //是否是企业老板
                                    status:'',//用户当前状态
                                    job:emp.position,//职位
                                    userEmail:emp.email,
                                    jobnumber:emp.jobnumber,   //用户工号
                                    userArea:emp.workPlace,//用户所在区域
                                    timestamp:moment().format('YYYY-MM-DD HH:mm:ss'),
                                    comment:1
                                })
                               // console.log(b,empindex,id)
                            }
                           
                        }
                    }
                }
                /* let data4=await dTalkApi.getDeptDetail(id);
                if(data4&&data4.name){
                    console.log(data4.name)
                } */
            }
        } 
        console.log('获取部门人员结束!!!!!!!!!!',moment().format('YYYY-MM-DD HH:mm:ss'))
        return {code:0}
    }

    





}
let addService=new AddService();
export default addService;